Repository navigation
Conversation
A Boolean array used as the whole index now selects what NumPy selects. A 1-D mask over the first of several axes is read as an orthogonal selection, an N-D mask over the leading axes as coordinates broadcast against the trailing axes, and an empty mask selects nothing whatever its shape. Full-shape masks keep the mask selection path, including on arrays with a zero-length axis. Orthogonal selection also accepts an empty Boolean array, and no longer fails on a zero-length dimension. Assisted-by: ClaudeCode:claude-opus-5-5
Assisted-by: ClaudeCode:claude-opus-5-5
`z[m2, :]` with a 2-D mask used to fail with "Boolean arrays in an orthogonal selection must be 1-dimensional only", which names an indexing mode the caller never asked for. The error now says that such an array is only supported as the whole index and suggests alternatives. Assisted-by: ClaudeCode:claude-opus-5-5
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 AI text below 🤖
Indexing an array with a Boolean NumPy array now selects what NumPy selects. That covers a mask over the leading axes (for example a
(2, 3)mask on a(2, 3, 4)array), an empty mask whose length is 0 along an axis, and a full-shape mask on an array with a zero-length axis. Orthogonal selection also accepts an empty Boolean array and no longer fails on a zero-length dimension. A Boolean array with more than one dimension inside a selection tuple, which is not supported, now raises an error that says so instead of one about orthogonal selection.What changed
expand_bool_indexinsrc/zarr/core/indexing.pyrewrites a Boolean array used as the whole index into a selection that the existing indexers already handle, following NumPy's reading of a maskmasm.nonzero():IndexError. As in NumPy, an empty mask may have length 0 along an axis; any other mismatch raises.Array.__getitem__,Array.__setitem__andget_indexercall it before dispatch.BoolArrayDimIndexeraccepts a zero-length Boolean array and computes its item count without indexing an empty cumulative sum, which crashed on a zero-length dimension on main. Thevindexcontract (coordinate arrays, or one full-shape mask) is unchanged.Verification
Known limits
z[m2] = np.arange(4)on a(2, 3, 4)array still raises.z[m2, 1]orz[m2, :], still raises, now with an error that says such a mask is only supported as the whole index (it used to talk about orthogonal selection). Supporting it would mean turning every slice in the tuple into coordinates, so it is left for a move onto zarr-indexing, whosevindexkeeps those axes lazy.z[np.True_]) still raises; NumPy adds a length-1 axis.z[E, E]with two empty masks gives(0, 0)where NumPy gives(0,).a[m, ...]with an index array before an Ellipsis still fails; that is fixed separately.Bookkeeping
This replaces zarr-developers#4519, which fixed the 1-D partial mask but sent empty full-shape masks on arrays with a zero-length axis down the orthogonal path, where they fail; those work on main. The Ellipsis case is zarr-developers#4595. If this is upstreamed, rename the changelog fragment to the upstream PR number.
🤖 Generated with Claude Code